<?php

/**
 *    此文件是流程模块【worc.文档分区】对应控制器接口文件。
 */
class mode_worcClassAction extends inputAction
{

    //获取分区列表
    public function getworcAjax()
    {
        return m('worc')->getmywroc();
    }

    /**
     *    获取文件
     */
    public function getfiledataAjax()
    {
        return m('word')->getdata();
    }


    /**
     *    保存上传的文件
     */
    public function savefileAjax()
    {
        m('word')->savefile();
        echo 'ok';
    }

    /**
     *    更新保存上传的文件
     */
    public function savefileupdateAjax()
    {
        m('word')->savefileupdate();
        echo 'ok';
    }

    /**
     *    创建文件夹
     */
    public function createfolderAjax()
    {
        $cqid = (int)$this->post('cqid');
        $typeid = (int)$this->post('typeid', '0');
        $name = $this->post('name');

        m('word')->createfolder($name, $cqid, $typeid);
    }

    /**
     *    删除
     */
    public function delfileAjax()
    {
        $id = (int)$this->post('id', '0');
        return m('word')->delword($id);
    }

    /**
     *   回收站
     */
    public function recycleAjax()
    {
        $id = (int)$this->post('id', '0');
        $ac = $this->post('ac', '');
        if (!$id || !$ac) {
            return returnerror('参数错误');
        }
        return m('word')->recycleword($id, $ac);
    }

    /**
     *    文件恢复
     */
    public function recyclefileAjax()
    {
        $ids = trim($this->post('id', ''));
        $cqid = (int)$this->post('cqid', '');
        $typeid = (int)$this->post('typeid', '');

        if (!$ids) {
            return returnerror('参数错误');
        }
        $fids = explode(",", $ids);
        $mids = [];
        foreach ($fids as $k => $v) {
            $op = m('file');
            $d = $op->getone($v);
            $opw = m('word');
            //文档中心处理
            if ($d['mknum'] == 'word') {

                $rst = $opw->update("`status`=1", "`fileid`=$v");

                $rst = $op->update("`status`=1", $v);

                $rst = m('word')->movefiles($cqid, $typeid, $d['mid']);
                //文档写作处理
            } else if ($d['mknum'] == 'wordxie' || $d['mknum'] == 'wordeil') {
                //创建文档
                $wordid = $opw->insert(array(
                    'optid' => $d['optid'],
                    'optname' => $d['optname'],
                    'fileid' => $v,
                    'optdt' => $d['adddt'],
                    'typeid' => $typeid,
                    'cid' => $cqid,
                    'comid' => $d['comid'],
                ));
                //更改状态
                $rst = $op->update(array(
                    'mid' => $wordid,
                    'mtype' => 'word',
                    'mknum' => 'word',
                    'status' => 1,
                ), $v);

            }
        }
        if ($rst) {
            return returnsuccess();

        } else {
            return returnerror('恢复失败');
        }
    }

    /**
     *   获取文件信息
     */
    public function getfileinfoAjax()
    {

        $id = (int)$this->post('id', '0');
        $ac = $this->post('ac', '');
        if (!$id || !$ac) {
            return returnerror('参数错误');
        }
        return m('word')->recycleword($id, $ac);
    }

    /**
     *    共享
     */
    public function sharefileAjax()
    {
        m('word')->sharefile();
    }

    public function movegetAjax()
    {
        return m('word')->getworcfolder();
    }

    public function movefileAjax()
    {
        return m('word')->movefile();
    }

    public function getmyinfoAjax()
    {
        return array(
            'uid' => 'u' . $this->adminid . '',
            'uname' => $this->adminname,
        );
    }

    //获取加密地址
    public function getsesfileurlAjax()
    {
        $url = getconfig('sesfile_url', 'http://www.sesoffice.cn/?website/13.html');
        $data = [
            'data' => $url,
        ];
        return returnsuccess($data);
    }
}	
			